version: "3.7"

services:
  mysql:
    image: "mysql:8"
    container_name: mysql
    hostname: mysql
    restart: always
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: 1234
    volumes:
      - ./mysqldata:/var/lib/mysql/
      - ../initsql:/docker-entrypoint-initdb.d/
      - ./etc-mysql/my.cnf:/etc/my.cnf
    network_mode: host

  redis:
    image: "redis:6.2"
    container_name: redis
    hostname: redis
    restart: always
    environment:
      TZ: Asia/Shanghai
    network_mode: host

  prometheus:
    image: prom/prometheus:v2.55.1
    container_name: prometheus
    hostname: prometheus
    restart: always
    environment:
      TZ: Asia/Shanghai
    volumes:
      - ./etc-prometheus:/etc/prometheus
    network_mode: host
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--storage.tsdb.path=/prometheus"
      - "--web.console.libraries=/usr/share/prometheus/console_libraries"
      - "--web.console.templates=/usr/share/prometheus/consoles"
      - "--enable-feature=remote-write-receiver"
      - "--query.lookback-delta=2m"

  n9e:
    image: flashcatcloud/nightingale:latest
    container_name: n9e
    hostname: n9e
    restart: always
    environment:
      GIN_MODE: release
      TZ: Asia/Shanghai
      WAIT_HOSTS: 127.0.0.1:3306, 127.0.0.1:6379
    volumes:
      - ./etc-nightingale:/app/etc
    network_mode: host
    depends_on:
      - mysql
      - redis
      - prometheus
    command: >
      sh -c "/app/n9e"

  categraf:
    image: "flashcatcloud/categraf:latest"
    container_name: "categraf"
    hostname: "categraf01"
    restart: always
    environment:
      TZ: Asia/Shanghai
      HOST_PROC: /hostfs/proc
      HOST_SYS: /hostfs/sys
      HOST_MOUNT_PREFIX: /hostfs
      WAIT_HOSTS: 127.0.0.1:17000, 127.0.0.1:20090
    volumes:
      - ./etc-categraf:/etc/categraf/conf
      - /:/hostfs
    network_mode: host
    depends_on:
      - n9e

  loki:
    image: grafana/loki:3.4.2
    container_name: loki
    hostname: loki
    restart: always
    volumes:
      - ./etc-loki/loki-config.yaml:/etc/loki/local-config.yaml
    command: -config.file=/etc/loki/local-config.yaml
    network_mode: host

  alloy:
    image: grafana/alloy:latest
    container_name: alloy
    hostname: alloy
    restart: always
    network_mode: host
    volumes:
      - ./etc-alloy/config.alloy:/etc/alloy/config.alloy
      - ./alloydata:/var/lib/alloy/data
    command: [
      "run",
      "--server.http.listen-addr=0.0.0.0:12345",
      "--storage.path=/var/lib/alloy/data",
      "/etc/alloy/config.alloy"
    ]

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    hostname: grafana
    restart: always
    network_mode: host
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
        - name: Loki
          type: loki
          access: proxy 
          orgId: 1
          url: http://127.0.0.1:3100
          basicAuth: false
          isDefault: true
          version: 1
          editable: false
        EOF
        /run.sh


